// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import MintUI from 'mint-ui'
import VueAwesomeSwiper from 'vue-awesome-swiper'
import VueScroller from 'vue-scroller'
import 'mint-ui/lib/style.css'
import 'styles/reset.css'
import 'styles/iconfont/iconfont.css'
import 'styles/iconfont2/iconfont.css'
import 'swiper/dist/css/swiper.css'
import $ from 'jquery'
// des加密解密
import { encryptDes, decryptDes } from './store/des'
Vue.prototype.encryptDes=encryptDes;Vue.prototype.encryptDes = encryptDes;Vue.prototype.encryptDes=encryptDes;Vue.prototype.decryptDes = decryptDes;
// md5加密
import md5 from 'js-md5';
Vue.prototype.$md5 = md5;
Vue.config.productionTip = false
Vue.use(VueAwesomeSwiper)
Vue.use(VueScroller)
//过滤文字长度
Vue.filter('ellipses', function (value,len) {
  // console.log(value,len)

  // value = value.toString();
  var val = value;
  if (typeof val != "string"){  
      val += "";  
    }  
  val = val.replace(/[^\x00-\xff]/g,"01"); 
	if (val.length > parseInt(len)*2){
    // console.log(val.length,value)
    var re = new RegExp("^[a-zA-Z]"); 
    if (re.test(value)) { 
      value = value.substr(0,len*2)+'...';
    } else{
      value = value.substr(0,len)+'...';
    }
    
  }
  return  value;
})
//内容为空或null,返回-
Vue.filter('textNull', function (value) {
	if (typeof value == 'number') {
		var value = value.toString();
	}
	if(value == ''|| value == null || value == undefined){
    	return '-';
	}else{
		return value
	}
})

router.beforeEach((to, from, next) => {
    let head = document.getElementsByTagName('head');

    let metaViewport = document.createElement('meta'),
        metarReferrer = document.createElement('meta');
    metaViewport.name = "viewport";
    metaViewport.content = 'width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no';
    metarReferrer.name = 'referrer'
    var referrer = $('head').find('meta[name="referrer"]'),
        viewport = $('head').find('meta[name="viewport"]');

    //referrer 网站对图片限制 ，设置meta no-referrer 不标记来源，可以正常加载图片
    if (referrer.length > 0) {//因为是间单页，所以要判断是不是首次
      if (to.meta.content) {
        metarReferrer.content = to.meta.content;
      }else{
        metarReferrer.content = ''
      }
    }else{//首次设置
      if (to.meta.content) {
        metarReferrer.content = to.meta.content;
        head[0].appendChild(metarReferrer)
      }
    }

    //禁止缩放
    if (viewport.length == 0) {//因为是间单页，所以要判断是不是首次
      head[0].appendChild(metaViewport)
    }else{
      viewport.attr('content','width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no')
    }

    if (to.meta.title) {
      document.title = to.meta.title
    }
    next()
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
